<?php 

/**
 * Global Helper Create By jefrisugiarto@yahoo.com
 * programer PHP, codeigniter, HTML, javascript,css 
 * @param array 
 * @return string
 */

 //print iklan
if (!function_exists('print_iklan')) {
    function print_iklan() {
        $iklan = '<div class="hr" style="margin-top: 10px;"></div>
                <div class="content content-full-width" style="color: white;background: #CDCDCD;padding-top:40px;padding-bottom: 40px;">
                    <div class="text_iklan">SPACE IKLAN</div>
                    <p>Mengenang Iklan Sepanjang Masa</p>
                </div>
                <div class="hr"></div>';
	return $iklan;
    }
}

if(!function_exists('session_data')) {
	function session_data() {
		$CI = & get_instance();
		$CI->load->library('session');
		$data = $CI->session->userdata('user');
		return $data;
	}
}

if(!function_exists('messageCheck')) {
	function MessageCheck($message) {
            $message=htmlspecialchars(stripslashes($message));
            $message=preg_replace('/((?:http|https|ftp):\/\/(?:[A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?[^\s\"\']+)/i','<a href="$1" rel="nofollow" target="blank">$1</a>',$message);
	    return $message;
	}
}


if(!function_exists('side_bar')) {
	function side_bar($title,$file) {
		$side = '<div class="widget widget_recent_entries">
                	<h2 class="widgettitle">'.$title.'</h2><ul>';
		foreach($file as $fl) {
                    $side .= '<li>
                        <a href="#" title="" class="thumb">
                            <img src="'.$this->config->item('images').'post-images/recent-post1.jpg" alt="" title="" />
                        </a>
			<h6> <a href="blog-single.html" title="">'.$fl->title.'</a> </h6>
			<p>'.$fl->keterangan.'</p>
                    </li>';
		}
		$side .= '</ul></div>';
	}
}

if(!function_exists('DataUser')) {
	function DataUser() {
		$CI = & get_instance();
		$CI->load->library('session');
		$data = session_data();
		if(!empty($data)) {
			if($data['otoritas']=='siswa') {
				$CI->load->model('siswamodel');
				$result = $CI->siswamodel->get_siswa($data['id_pengguna']);
				return $result;
			}else{
				$CI->load->model('pegawaimodel');
				$result = $CI->pegawaimodel->get_pegawai($data['id_pengguna']);
				return $result;
			}
		}
	}
}

if(!function_exists('CheckTime')) {
	function CheckTime($dt,$precision=2)
	{
        if(is_string($dt)) $dt=strtotime($dt);
	$times=array(	365*24*60*60	=> "year",
					30*24*60*60	=> "month",
					7*24*60*60	=> "week",
					24*60*60	=> "day",
					60*60		=> "hour",
					60		=> "minute",
					1		=> "second");
	
	$passed=time()-$dt;	
	if($passed<5)
	{
            $output='less than 5 seconds ago';
	}
	else
	{
            $output=array();
            $exit=0;
            foreach($times as $period=>$name)
            {
                    if($exit>=$precision || ($exit>0 && $period<60)) break;	
                    $result = floor($passed/$period);
                    if($result>0)
                    {
                            $output[]=$result.' '.$name.($result==1?'':'s');
                            $passed-=$result*$period;
                            $exit++;
                    }
                    else if($exit>0) $exit++;
            }			
            $output=implode(' and ',$output).' ago';
	}
	return $output;
    }
}


